package com.example.demo.dao1;

import com.example.demo.entity.Stucu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface StuJpaDao extends JpaRepository<Stucu, Integer> {
    List<Stucu> findByNameNotNull();

    @Query("select c from stu c where c.id=?1")
    Stucu getOnes(int id);

    @Query(
            value = "select * from stu where id=?1",
            nativeQuery = true
    )
    Stucu getOneBy(int id);

    @Transactional
    @Modifying
    @Query(
            value = "update stu set name=?2 where id=?1",
            nativeQuery = true
    )
    int updateStu(int id, String newName);

    List<Stucu> findByNameContaining(String name);

    List<Stucu> findByNameContainingAndAge(String name, int age);

    List<Stucu> findByNameContainingAndAgeBetweenAndSex(String name, int age1, int age2, String sex);

    List<Stucu> findBySex(String sex);

    List<Stucu> findByClassId(int classId);

    List<Stucu> findByNameOrName(String name, String name2);
}
